$().ready(function(){
	tr.$f = $('#first_area');
	tr.$s = $('#second_area');
	tr.$t = $('#third_area');
	tr.bind();
});

tr = {};

tr.bind = function(){
	tr.$f.change(function(){
		pid = this.value;
		tr.first(pid);
	});
	tr.$s.change(function(){
		tr.second(this.value);
	});
};

tr.first = function(pid){
	callback = function(data){
		var html = jQuery(data.html).html();
		tr.$s.html(html).change();
	}
	tr.action(pid,callback);
};

tr.second = function(pid){
	callback = function(data){
		var html = jQuery(data.html).html();
		tr.$t.html(html).change();
	}
	tr.action(pid,callback);
};

tr.action = function(pid,callback){
	if (pid == '' || pid == '0') {
		data = {}; 
		data.html = '<select><option>请选择</option></select>';
		callback(data);
		return ;
	};
	jQuery.ajax({
			type:'get',
			url:GM.rootUrl+'admin/areas/Areas/getSonOption/'+pid+'/false/1',
			dataType:'json',
			success : function(data){
				if(data.state){
					callback(data);
				}
			},
			error : function(e){
				alert(e);
			},
			complete:function(){
			}
		});	
	
};
